﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.Serialization;

namespace QbservableCore.Serialization
{
    [DataContract]
    public class MemberAssignmentNode : MemberBindingNodeBase
    {
        [DataMember]
        public ExpRepresentationBase AssignedExpression { get; set; }

        protected internal override void TraverseChildren(Func<ExpRepresentationBase, ExpRepresentationBase> action)
        {
            AssignedExpression = AssignedExpression.Traverse(action);
        }

        public override string ToString()
        {
            return MemberName + " = " + AssignedExpression.ToString();
        }

        protected internal override MemberBinding ToMemberBindingCore(ExepressionBuilderCache exepressionBuilderCache, MemberInfo member)
        {
            return Expression.Bind(member, AssignedExpression.ToExpression(exepressionBuilderCache));
        }
    }
}
